﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MountSilverLibraryRemake
{
    public partial class MountSilverLibraryRemake : Form
    {
        Trans trans;
        public MountSilverLibraryRemake()
        {
            InitializeComponent();
        }
        public MountSilverLibraryRemake(ref Trans trans)
        {
            InitializeComponent();
            this.trans = trans;
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            String loginConnection = "server=localhost;user id=root;password=root;database=mountsilverlibraryremake";
            MySqlConnection connectionLogin = new MySqlConnection(loginConnection);
            try
            {
                connectionLogin.Open();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.StackTrace);
            }
            String loginCommand = "select * from users where `username`=" + "\'"+username.Text+"\'" + " and `password`=" + "\'"+password.Text+"\'";
            MySqlCommand commandLogin = new MySqlCommand(loginCommand,connectionLogin);
            MySqlDataReader logindr = commandLogin.ExecuteReader();
            if (logindr.Read())
            {
                MessageBox.Show("欢迎进入图书管理系统," + username.Text);
                this.trans.setUsernameTrans(username.Text);
                this.trans.setPasswordTrans(password.Text);
                this.trans.setLoginFlag(1);
                this.Close();
            }
            else
            {
                MessageBox.Show("用户名或者密码错误");
                username.Clear();
                password.Clear();
            }
            try
            {
                connectionLogin.Close();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.StackTrace);
            }
        }
    }
}
